package com.example.fineTuning;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;

public class FineTuning {

    /*
    *
{
    "object": "file",
    "id": "file-YbUDb9A738SeJSzp4VtPLsYm",
    "purpose": "fine-tune",
    "filename": "m.jsonl",
    "bytes": 2364,
    "created_at": 1693288753,
    "status": "uploaded",
    "status_details": null
}
    * */

    private static final String AI_KEY = "Bearer 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";
    //创建微调
    private static final String AI_URL_JOBS = "https://api.openai.com/v1/fine_tuning/jobs";

    public void jobs() {
        HttpRequest post = HttpRequest.post(AI_URL_JOBS);
        post.contentType("application/json");
        post.header("Authorization", AI_KEY);
        FineTuningParam param = new FineTuningParam();
        param.setModel("gpt-3.5-turbo-0613");
        param.setTraining_file("file-YbUDb9A738SeJSzp4VtPLsYm");
        post.body(JSONUtil.toJsonStr(param));
        post.setHttpProxy("127.0.0.1", 7078);
        System.out.println(post);
        HttpResponse response = post.execute();
        System.out.println(response.body());

        //{"object":"fine_tuning.job","id":"ftjob-lbNo58wRGYkXKOha1VeonVbU","model":"gpt-3.5-turbo-0613","created_at":1693288779,"finished_at":null,"fine_tuned_model":null,"organization_id":"org-BRUOIsHdY0w2e2yJ2EY2Vx3c","result_files":[],"status":"created","validation_file":null,"training_file":"file-YbUDb9A738SeJSzp4VtPLsYm","hyperparameters":{"n_epochs":10},"trained_tokens":null}
    }

    public static void main(String[] args) {
        FineTuning fineTuning = new FineTuning();
        fineTuning.jobs();
    }

}
